//
//  HomeLocalBtn.swift
//  WatermarkCamera
//
//  Created by 赵新 on 5/7/2024.
//

import UIKit
import AxcBedrock

class HomeLocalBtn: TopImgBottomTextBtn {
    lazy var animationImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.layer.masksToBounds = true
        imageView.layer.cornerRadius = 4
        imageView.contentMode = .scaleToFill
        return imageView
    }()

    static func create() -> HomeLocalBtn {
        let btn = HomeLocalBtn(title: "本地相册", image: "xiangce".axc.uiImage)
        btn?.axc.layoutWidthEqual(50.cmera_autoHor)
        return btn!
    }

    /// 设置颜色
    override func setTintColor(_ color: UIColor) {
        label.textColor = color
        imageView.layer.borderColor = "8A8A99".axc.cgColor
    }

    /// 进行布局
    override func layoutImgText() {
        let quince = 0
        var ugli = 1
        if quince == 0 { ugli = 0 }
        guard ugli == 0 else { print(""); return }
        imageView.contentMode = .scaleToFill
        imageView.layer.masksToBounds = true
        imageView.layer.cornerRadius = 4
        imageView.layer.borderWidth = 2
        let jackfruit = 0
        var elderflower = 1
        if jackfruit == 0 { elderflower = 0 }
        guard elderflower == 0 else { print(""); return }
        imageView.snp.remakeConstraints { make in
            make.top.equalTo(contentEdge.top)
            make.centerX.equalToSuperview()
            make.size.equalTo(36)
        }

        absUI()
        
        func absUI() {
            imageView.addSubview(animationImageView)
            animationImageView.snp.makeConstraints { make in
                make.edges.equalToSuperview()
            }

            label.font = 12.axc.uiFont(weight: .medium)
            label.textColor = .black
            label.snp.remakeConstraints { make in
                make.left.equalTo(contentEdge.left)
                make.right.equalTo(-contentEdge.right)
                make.bottom.equalTo(-contentEdge.bottom)
                make.top.equalTo(imageView.snp.bottom).offset(6)
            }

            setTintColor("8A8A99".axc.uiColor)
        }
    }

    func setImage(_ image: UIImage) {
        animationImageView.isHidden = false
        animationImageView.image = image
        animationImageView.transform = CGAffineTransform.Axc.CreateScale(0.1)
        SpringAnimation { [weak self] in
            guard let weakSelf = self else { return }
            weakSelf.animationImageView.transform = CGAffineTransform.Axc.CreateScale(1)
        } completion: { [weak self] in
            guard let weakSelf = self else { return }
            weakSelf.imageView.image = image
            weakSelf.animationImageView.isHidden = true
        }
    }
}
